<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class MY_Controller extends Controller {
	var $flag = "";
	
	function My_Controller($flag = "") {
		parent::Controller ();
		$this->load->library ( 'session' );
		$this->flag = $flag;
		if ($flag == "") {
			$user_id = $this->session->userdata ( 'user_id' );
			if (! $user_id) {
				redirect ( 'user/UserAction/login' );
			}
		} else if ($flag == "wedding") {
			$user_id = $this->session->userdata ( 'wedding_id' );
			if (! $user_id) {
				redirect ( 'wedding/weddingAction/login' );
			}
		}
	
	}
	
	function _get_wedding_path() {
		if ($this->flag == "wedding") {
			$base_path = $_SERVER ['DOCUMENT_ROOT'];
			if (! file_exists ( $base_path . "upload/wedding/" . $this->session->userdata ( 'wedding_date' ) . "/" )) {
				mkdir ( $base_path . "upload/wedding/" . $this->session->userdata ( 'wedding_date' ) . "/" );
			}
			if (! file_exists($base_path . "upload/wedding/" . $this->session->userdata ( 'wedding_date' ) . "/" . $this->session->userdata ( 'wedding_id' )."/")) {
				mkdir ($base_path . "upload/wedding/" . $this->session->userdata ( 'wedding_date' ) . "/" . $this->session->userdata ( 'wedding_id' )."/");
			}
			return "upload/wedding/" . $this->session->userdata ( 'wedding_date' ) . "/" . $this->session->userdata ( 'wedding_id' )."/";
		}
	}
	
	function _set_ajax_head() {
		$this->output->set_header ( "HTTP/1.0 200 OK" );
		$this->output->set_header ( "HTTP/1.1 200 OK" );
		$this->output->set_header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s', time () ) . ' GMT' );
		$this->output->set_header ( "Cache-Control: no-store, no-cache, must-revalidate" );
		$this->output->set_header ( "Cache-Control: post-check=0, pre-check=0" );
		$this->output->set_header ( "Pragma: no-cache" );
	}
	
	function _form_data($del_fields = false) {
		$form_data = array ();
		if ($_POST) {
			if ($del_fields) {
				foreach ( $_POST as $k => $v ) {
					if (! in_array ( $k, $del_fields )) {
						$form_data [$k] = $v;
					}
				}
			} else {
				foreach ( $_POST as $k => $v ) {
					$form_data [$k] = $v;
				}
			}
		}
		return $form_data;
	}
	
	function _debug($data) {
		echo "<pre>";
		print_r ( $data );
	}

}